package ar.republicagroup.gestion.dao.jpa;

import ar.republicagroup.gestion.dao.MovimientoTipoDAO;
import ar.republicagroup.gestion.entities.MovimientoTipo;
import ar.republicagroup.gestion.util.JPAUtil;
import javax.persistence.EntityManager;
import javax.persistence.Query;

/**
 *
 * @author DIEGOALV
 */
public class MovimientoTipoDAOImplJPA implements MovimientoTipoDAO {

    
    private EntityManager em;
    
    public MovimientoTipoDAOImplJPA(){
        em = JPAUtil.getEntityManager();
    }
    
    @Override
    public MovimientoTipo getMovimientoTipoByName(String name) {
        if(!em.isOpen()){ em = JPAUtil.getEntityManager(); }
        
        Query query = em.createQuery("SELECT m FROM MovimientoTipo m WHERE m.nombre = ?1");
        query.setParameter(1, name);
        return (MovimientoTipo)query.getSingleResult();
    }
    
}
